package com.it.applet;

import com.it.applet.studio.IntCanvas;
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.BoxPane;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.ComponentListener;
import org.apache.pivot.wtk.DesktopApplicationContext;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.Window;
import org.apache.pivot.wtk.media.Drawing;
import org.apache.pivot.wtkx.WTKXSerializer;

public class INTClientWTKX implements Application {

  private Window window = null;

  @Override
  public void startup(Display display, Map<String, String> properties)
          throws Exception {
    final WTKXSerializer wtkxSerializer = new WTKXSerializer();
    window = (Window) wtkxSerializer.readObject(this, "client.wtkx.xml");
    final BoxPane boxPane = (BoxPane) wtkxSerializer.get("intBoxPane");
    boxPane.getComponentListeners().add(new ComponentListener.Adapter() {

      @Override
      public void sizeChanged(Component component, int previousWidth,
                              int previousHeight) {
        IntCanvas canvas = (IntCanvas) wtkxSerializer.get("intCanvas");
        canvas.setSize(boxPane.getWidth(), boxPane.getHeight());
      }
    });
    window.open(display);
  }

  @Override
  public boolean shutdown(boolean optional) {
    if (window != null) {
      window.close();
    }

    return false;
  }

  @Override
  public void suspend() {
  }

  @Override
  public void resume() {
  }

  public static void main(String[] args) {
    DesktopApplicationContext.main(INTClientWTKX.class, args);
  }
}
